<?php

namespace App\Admin\Controllers;

use App\Models\Order;
use App\Models\OrderRefund;
use App\User;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class OrderRefundController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '退货申请';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new OrderRefund);

        $grid->column('id', __('ID'));
        $grid->column('name', __('收货人'))->display(function(){
            $order = Order::find($this->order_id);
            if($order){
                return $order['contact_name'];
            }
            return '';
        });
        $grid->column('mobile', __('收货电话'))->display(function(){
            $order = Order::find($this->order_id);
            if($order){
                return $order['contact_phone'];
            }
            return '';
        });
        $grid->column('order_id', __('订单号'))->display(function(){
           $order = Order::find($this->order_id);
           if($order){
               return $order['no'];
           }
           return '';
        });
        $grid->column('refund_status', __('处理状态'))->editable('select',OrderRefund::REFUND);
        $grid->column('reason', __('Reason'));
        //$grid->column('imgs', __('Imgs'));
        $grid->column('created_at', __('申请时间'));
       //$grid->column('updated_at', __('Updated at'));

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(OrderRefund::findOrFail($id));

        $show->field('refund_id', __('Refund id'));
        $show->field('user_id', __('User id'));
        $show->field('order_id', __('Order id'));
        $show->field('refund_status', __('Refund status'));
        $show->field('reason', __('Reason'));
        $show->field('imgs', __('Imgs'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new OrderRefund);

        $form->textarea('reason', __('退货原因'))->readonly();
        $form->multipleImage('imgs', __('退货截图'))->readonly();
        $form->select('refund_status','处理状态')->options(OrderRefund::REFUND);
        $form->textarea('remark', __('审核意见'));

        return $form;
    }
}
